{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import os, sys\n",
    "\n",
    "import lasio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def print2(msg):\n",
    "    for i, line in enumerate(msg.splitlines()):\n",
    "        print \"Line %d:%s\" % (i, line.strip(\"\\n\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Line 0:~Version Information\n",
      "Line 1: VERS.                1.20:   CWLS log ASCII Standard -VERSION 1.20\n",
      "Line 2: WRAP.                 YES:   Multiple lines per depth step\n",
      "Line 3:~Well Information\n",
      "Line 4:#MNEM.UNIT       Data Type    Information\n",
      "Line 5:#---------    -------------   ------------------------------\n",
      "Line 6: STRT.M            910.000:\n",
      "Line 7: STOP.M            901.000:\n",
      "Line 8: STEP.M            -0.1250:\n",
      "Line 9: NULL.           -999.2500:   Null value\n",
      "Line 10: COMP.             COMPANY:   ANY OIL COMPANY INC.\n",
      "Line 11: WELL.                WELL:   ANY ET AL XX-XX-XX-XX\n",
      "Line 12: FLD .               FIELD:   WILDCAT\n",
      "Line 13: LOC .            LOCATION:   XX-XX-XX-XXW3M\n",
      "Line 14: PROV.            PROVINCE:   SASKATCHEWAN\n",
      "Line 15: SRVC.     SERVICE COMPANY:   ANY LOGGING COMPANY INC.\n",
      "Line 16: SON .     SERVICE ORDER :   142085\n",
      "Line 17: DATE.            LOG DATE:   13-DEC-86\n",
      "Line 18: UWI .      UNIQUE WELL ID:\n",
      "Line 19:~Curve Information\n",
      "Line 20:#MNEM.UNIT      API CODE      Curve Description\n",
      "Line 21:#---------    -------------   ------------------------------\n",
      "Line 22: DEPT.M                       :    Depth\n",
      "Line 23: DT  .US/M                    :  1 Sonic Travel Time\n",
      "Line 24: RHOB.K/M                     :  2 Density-Bulk Density\n",
      "Line 25: NPHI.V/V                     :  3 Porosity -Neutron\n",
      "Line 26: RX0 .OHMM                    :  4 Resistivity -Rxo\n",
      "Line 27: RESS.OHMM                    :  5 Resistivity -Shallow\n",
      "Line 28: RESM.OHMM                    :  6 Resistivity -Medium\n",
      "Line 29: RESD.OHMM                    :  7 Resistivity -Deep\n",
      "Line 30: SP  .MV                      :  8 Spon. Potential\n",
      "Line 31: GR  .GAPI                    :  9 Gamma Ray\n",
      "Line 32: CALI.MM                      : 10 Caliper\n",
      "Line 33: DRHO.K/M3                    : 11 Delta-Rho\n",
      "Line 34: EATT.DBM                     : 12 EPT Attenuation\n",
      "Line 35: TPL .NS/M                    : 13 TP -EPT\n",
      "Line 36: PEF .                        : 14 PhotoElectric Factor\n",
      "Line 37: FFI .V/V                     : 15 Porosity -NML FFI\n",
      "Line 38: DCAL.MM                      : 16 Caliper-Differential\n",
      "Line 39: RHGF.K/M3                    : 17 Density-Formation\n",
      "Line 40: RHGA.K/M3                    : 18 Density-Apparent\n",
      "Line 41: SPBL.MV                      : 19 Baselined SP\n",
      "Line 42: GRC .GAPI                    : 20 Gamma Ray BHC\n",
      "Line 43: PHIA.V/V                     : 21 Porosity -Apparent\n",
      "Line 44: PHID.V/V                     : 22 Porosity -Density\n",
      "Line 45: PHIE.V/V                     : 23 Porosity -Effective\n",
      "Line 46: PHIN.V/V                     : 24 Porosity -Neut BHC\n",
      "Line 47: PHIC.V/V                     : 25 Porosity -Total HCC\n",
      "Line 48: R0  .OHMM                    : 26 Ro\n",
      "Line 49: RWA .OHMM                    : 27 Rfa\n",
      "Line 50: SW   .                       : 28 Sw -Effective\n",
      "Line 51: MSI .                        : 29 Sh Idx -Min\n",
      "Line 52: BVW .                        : 30 BVW\n",
      "Line 53: FGAS.                        : 31 Flag -Gas Index\n",
      "Line 54: PIDX.                        : 32 Prod Idx\n",
      "Line 55: FBH .                        : 33 Flag -Bad Hole\n",
      "Line 56: FHCC.                        : 34 Flag -HC Correction\n",
      "Line 57: LSWB.                        : 35 Flag -Limit SWB\n",
      "Line 58:~A Log data section\n",
      "Line 59:910.000000\n",
      "Line 60:  -999.2500  2692.7075     0.3140    19.4086    19.4086    13.1709    12.2681\n",
      "Line 61:    -1.5010    96.5306   204.7177    30.5822  -999.2500  -999.2500     3.2515\n",
      "Line 62:  -999.2500     4.7177  3025.0264  3025.0264    -1.5010    93.1378     0.1641\n",
      "Line 63:     0.0101     0.1641     0.3140     0.1641    11.1397     0.3304     0.9529\n",
      "Line 64:     0.0000     0.1564     0.0000    11.1397     0.0000     0.0000     0.0000\n",
      "Line 65:909.875000\n",
      "Line 66:  -999.2500  2712.6460     0.2886    23.3987    23.3987    13.6129    12.4744\n",
      "Line 67:    -1.4720    90.2803   203.1093    18.7566  -999.2500  -999.2500     3.7058\n",
      "Line 68:  -999.2500     3.1093  3004.6050  3004.6050    -1.4720    86.9078     0.1456\n",
      "Line 69:    -0.0015     0.1456     0.2886     0.1456    14.1428     0.2646     1.0000\n",
      "Line 70:     0.0000     0.1456     0.0000    14.1428     0.0000     0.0000     0.0000\n",
      "Line 71:909.750000\n",
      "Line 72:  -999.2500  2692.8137     0.2730    22.5909    22.5909    13.6821    12.6146\n",
      "Line 73:    -1.4804    89.8492   201.9287     3.1551  -999.2500  -999.2500     4.3124\n",
      "Line 74:  -999.2500     1.9287  2976.4451  2976.4451    -1.4804    86.3465     0.1435\n",
      "Line 75:     0.0101     0.1435     0.2730     0.1435    14.5674     0.2598     1.0000\n",
      "Line 76:     0.0000     0.1435     0.0000    14.5674     0.0000     0.0000     0.0000\n",
      "Line 77:909.625000\n",
      "Line 78:  -999.2500  2644.3650     0.2765    18.4831    18.4831    13.4159    12.6900\n",
      "Line 79:    -1.5010    93.3999   201.5826    -6.5861  -999.2500  -999.2500     4.3822\n",
      "Line 80:  -999.2500     1.5826  2955.3528  2955.3528    -1.5010    89.7142     0.1590\n",
      "Line 81:     0.0384     0.1590     0.2765     0.1590    11.8600     0.3210     0.9667\n",
      "Line 82:     0.0000     0.1538     0.0000    11.8600     0.0000     0.0000     0.0000\n",
      "Line 83:909.500000\n",
      "Line 84:  -999.2500  2586.2822     0.2996    13.9187    13.9187    12.9195    12.7016\n",
      "Line 85:    -1.4916    98.1214   201.7126    -4.5574  -999.2500  -999.2500     3.5967\n",
      "Line 86:  -999.2500     1.7126  2953.5940  2953.5940    -1.4916    94.2670     0.1880\n",
      "Line 87:     0.0723     0.1880     0.2996     0.1880     8.4863     0.4490     0.8174\n",
      "Line 88:     0.0000     0.1537     0.0000     8.4863     0.0000     0.0000     0.0000\n"
     ]
    }
   ],
   "source": [
    "l = lasio.read(os.path.join(\"..\", \"tests\", \"examples\", \"1.2\", \"sample_wrapped.las\"))\n",
    "print2(l._text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Show an unwrapped version"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HeaderItem(mnemonic=WRAP, unit=, value=YES, descr=Multiple lines per depth step, original_mnemonic=WRAP)\n",
      "\n",
      "Line 0:~Version ---------------------------------------------------\n",
      "Line 1:VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0\n",
      "Line 2:WRAP. YES : Multiple lines per depth step\n",
      "Line 3:~Well ------------------------------------------------------\n",
      "Line 4:STRT.M                   910.0 : \n",
      "Line 5:STOP.M                   909.5 : \n",
      "Line 6:STEP.M                  -0.125 : \n",
      "Line 7:NULL.                  -999.25 : Null value\n",
      "Line 8:COMP.     ANY OIL COMPANY INC. : COMPANY\n",
      "Line 9:WELL.    ANY ET AL XX-XX-XX-XX : WELL\n",
      "Line 10:FLD .                  WILDCAT : FIELD\n",
      "Line 11:LOC .           XX-XX-XX-XXW3M : LOCATION\n",
      "Line 12:PROV.             SASKATCHEWAN : PROVINCE\n",
      "Line 13:SRVC. ANY LOGGING COMPANY INC. : SERVICE COMPANY\n",
      "Line 14:SON .                   142085 : SERVICE ORDER\n",
      "Line 15:DATE.                13-DEC-86 : LOG DATE\n",
      "Line 16:UWI .                          : UNIQUE WELL ID\n",
      "Line 17:~Curves ----------------------------------------------------\n",
      "Line 18:DEPT.M     : Depth\n",
      "Line 19:DT  .US/M  : 1 Sonic Travel Time\n",
      "Line 20:RHOB.K/M   : 2 Density-Bulk Density\n",
      "Line 21:NPHI.V/V   : 3 Porosity -Neutron\n",
      "Line 22:RX0 .OHMM  : 4 Resistivity -Rxo\n",
      "Line 23:RESS.OHMM  : 5 Resistivity -Shallow\n",
      "Line 24:RESM.OHMM  : 6 Resistivity -Medium\n",
      "Line 25:RESD.OHMM  : 7 Resistivity -Deep\n",
      "Line 26:SP  .MV    : 8 Spon. Potential\n",
      "Line 27:GR  .GAPI  : 9 Gamma Ray\n",
      "Line 28:CALI.MM    : 10 Caliper\n",
      "Line 29:DRHO.K/M3  : 11 Delta-Rho\n",
      "Line 30:EATT.DBM   : 12 EPT Attenuation\n",
      "Line 31:TPL .NS/M  : 13 TP -EPT\n",
      "Line 32:PEF .      : 14 PhotoElectric Factor\n",
      "Line 33:FFI .V/V   : 15 Porosity -NML FFI\n",
      "Line 34:DCAL.MM    : 16 Caliper-Differential\n",
      "Line 35:RHGF.K/M3  : 17 Density-Formation\n",
      "Line 36:RHGA.K/M3  : 18 Density-Apparent\n",
      "Line 37:SPBL.MV    : 19 Baselined SP\n",
      "Line 38:GRC .GAPI  : 20 Gamma Ray BHC\n",
      "Line 39:PHIA.V/V   : 21 Porosity -Apparent\n",
      "Line 40:PHID.V/V   : 22 Porosity -Density\n",
      "Line 41:PHIE.V/V   : 23 Porosity -Effective\n",
      "Line 42:PHIN.V/V   : 24 Porosity -Neut BHC\n",
      "Line 43:PHIC.V/V   : 25 Porosity -Total HCC\n",
      "Line 44:R0  .OHMM  : 26 Ro\n",
      "Line 45:RWA .OHMM  : 27 Rfa\n",
      "Line 46:SW  .      : 28 Sw -Effective\n",
      "Line 47:MSI .      : 29 Sh Idx -Min\n",
      "Line 48:BVW .      : 30 BVW\n",
      "Line 49:FGAS.      : 31 Flag -Gas Index\n",
      "Line 50:PIDX.      : 32 Prod Idx\n",
      "Line 51:FBH .      : 33 Flag -Bad Hole\n",
      "Line 52:FHCC.      : 34 Flag -HC Correction\n",
      "Line 53:LSWB.      : 35 Flag -Limit SWB\n",
      "Line 54:~Params ----------------------------------------------------\n",
      "Line 55:~Other -----------------------------------------------------\n",
      "Line 56:~ASCII -----------------------------------------------------\n",
      "Line 57:  910.00000    -999.25 2692.70750    0.31400   19.40860   19.40860   13.17090   12.26810   -1.50100   96.53060  204.71770   30.58220    -999.25    -999.25    3.25150    -999.25    4.71770 3025.02640 3025.02640   -1.50100   93.13780    0.16410    0.01010    0.16410    0.31400    0.16410   11.13970    0.33040    0.95290    0.00000    0.15640    0.00000   11.13970    0.00000    0.00000    0.00000\n",
      "Line 58:  909.87500    -999.25 2712.64600    0.28860   23.39870   23.39870   13.61290   12.47440   -1.47200   90.28030  203.10930   18.75660    -999.25    -999.25    3.70580    -999.25    3.10930 3004.60500 3004.60500   -1.47200   86.90780    0.14560   -0.00150    0.14560    0.28860    0.14560   14.14280    0.26460    1.00000    0.00000    0.14560    0.00000   14.14280    0.00000    0.00000    0.00000\n",
      "Line 59:  909.75000    -999.25 2692.81370    0.27300   22.59090   22.59090   13.68210   12.61460   -1.48040   89.84920  201.92870    3.15510    -999.25    -999.25    4.31240    -999.25    1.92870 2976.44510 2976.44510   -1.48040   86.34650    0.14350    0.01010    0.14350    0.27300    0.14350   14.56740    0.25980    1.00000    0.00000    0.14350    0.00000   14.56740    0.00000    0.00000    0.00000\n",
      "Line 60:  909.62500    -999.25 2644.36500    0.27650   18.48310   18.48310   13.41590   12.69000   -1.50100   93.39990  201.58260   -6.58610    -999.25    -999.25    4.38220    -999.25    1.58260 2955.35280 2955.35280   -1.50100   89.71420    0.15900    0.03840    0.15900    0.27650    0.15900   11.86000    0.32100    0.96670    0.00000    0.15380    0.00000   11.86000    0.00000    0.00000    0.00000\n",
      "Line 61:  909.50000    -999.25 2586.28220    0.29960   13.91870   13.91870   12.91950   12.70160   -1.49160   98.12140  201.71260   -4.55740    -999.25    -999.25    3.59670    -999.25    1.71260 2953.59400 2953.59400   -1.49160   94.26700    0.18800    0.07230    0.18800    0.29960    0.18800    8.48630    0.44900    0.81740    0.00000    0.15370    0.00000    8.48630    0.00000    0.00000    0.00000\n"
     ]
    }
   ],
   "source": [
    "print l.version[\"WRAP\"]\n",
    "print\n",
    "s = lasio.las.StringIO()\n",
    "l.write(s, version=2, fmt=\"%.5f\")\n",
    "s.seek(0)\n",
    "print2(s.read())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Write un-wrapped version:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HeaderItem(mnemonic=WRAP, unit=, value=NO, descr=Multiple lines per depth step, original_mnemonic=WRAP)\n",
      "\n",
      "Line 0:~Version ---------------------------------------------------\n",
      "Line 1:VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0\n",
      "Line 2:WRAP.  NO : Multiple lines per depth step\n",
      "Line 3:~Well ------------------------------------------------------\n",
      "Line 4:STRT.M                   910.0 : \n",
      "Line 5:STOP.M                   909.5 : \n",
      "Line 6:STEP.M                  -0.125 : \n",
      "Line 7:NULL.                  -999.25 : Null value\n",
      "Line 8:COMP.     ANY OIL COMPANY INC. : COMPANY\n",
      "Line 9:WELL.    ANY ET AL XX-XX-XX-XX : WELL\n",
      "Line 10:FLD .                  WILDCAT : FIELD\n",
      "Line 11:LOC .           XX-XX-XX-XXW3M : LOCATION\n",
      "Line 12:PROV.             SASKATCHEWAN : PROVINCE\n",
      "Line 13:SRVC. ANY LOGGING COMPANY INC. : SERVICE COMPANY\n",
      "Line 14:SON .                   142085 : SERVICE ORDER\n",
      "Line 15:DATE.                13-DEC-86 : LOG DATE\n",
      "Line 16:UWI .                          : UNIQUE WELL ID\n",
      "Line 17:~Curves ----------------------------------------------------\n",
      "Line 18:DEPT.M     : Depth\n",
      "Line 19:DT  .US/M  : 1 Sonic Travel Time\n",
      "Line 20:RHOB.K/M   : 2 Density-Bulk Density\n",
      "Line 21:NPHI.V/V   : 3 Porosity -Neutron\n",
      "Line 22:RX0 .OHMM  : 4 Resistivity -Rxo\n",
      "Line 23:RESS.OHMM  : 5 Resistivity -Shallow\n",
      "Line 24:RESM.OHMM  : 6 Resistivity -Medium\n",
      "Line 25:RESD.OHMM  : 7 Resistivity -Deep\n",
      "Line 26:SP  .MV    : 8 Spon. Potential\n",
      "Line 27:GR  .GAPI  : 9 Gamma Ray\n",
      "Line 28:CALI.MM    : 10 Caliper\n",
      "Line 29:DRHO.K/M3  : 11 Delta-Rho\n",
      "Line 30:EATT.DBM   : 12 EPT Attenuation\n",
      "Line 31:TPL .NS/M  : 13 TP -EPT\n",
      "Line 32:PEF .      : 14 PhotoElectric Factor\n",
      "Line 33:FFI .V/V   : 15 Porosity -NML FFI\n",
      "Line 34:DCAL.MM    : 16 Caliper-Differential\n",
      "Line 35:RHGF.K/M3  : 17 Density-Formation\n",
      "Line 36:RHGA.K/M3  : 18 Density-Apparent\n",
      "Line 37:SPBL.MV    : 19 Baselined SP\n",
      "Line 38:GRC .GAPI  : 20 Gamma Ray BHC\n",
      "Line 39:PHIA.V/V   : 21 Porosity -Apparent\n",
      "Line 40:PHID.V/V   : 22 Porosity -Density\n",
      "Line 41:PHIE.V/V   : 23 Porosity -Effective\n",
      "Line 42:PHIN.V/V   : 24 Porosity -Neut BHC\n",
      "Line 43:PHIC.V/V   : 25 Porosity -Total HCC\n",
      "Line 44:R0  .OHMM  : 26 Ro\n",
      "Line 45:RWA .OHMM  : 27 Rfa\n",
      "Line 46:SW  .      : 28 Sw -Effective\n",
      "Line 47:MSI .      : 29 Sh Idx -Min\n",
      "Line 48:BVW .      : 30 BVW\n",
      "Line 49:FGAS.      : 31 Flag -Gas Index\n",
      "Line 50:PIDX.      : 32 Prod Idx\n",
      "Line 51:FBH .      : 33 Flag -Bad Hole\n",
      "Line 52:FHCC.      : 34 Flag -HC Correction\n",
      "Line 53:LSWB.      : 35 Flag -Limit SWB\n",
      "Line 54:~Params ----------------------------------------------------\n",
      "Line 55:~Other -----------------------------------------------------\n",
      "Line 56:~ASCII -----------------------------------------------------\n",
      "Line 57:  910.00000    -999.25 2692.70750    0.31400   19.40860   19.40860   13.17090   12.26810   -1.50100   96.53060  204.71770   30.58220    -999.25    -999.25    3.25150    -999.25    4.71770 3025.02640 3025.02640   -1.50100   93.13780    0.16410    0.01010    0.16410    0.31400    0.16410   11.13970    0.33040    0.95290    0.00000    0.15640    0.00000   11.13970    0.00000    0.00000    0.00000\n",
      "Line 58:  909.87500    -999.25 2712.64600    0.28860   23.39870   23.39870   13.61290   12.47440   -1.47200   90.28030  203.10930   18.75660    -999.25    -999.25    3.70580    -999.25    3.10930 3004.60500 3004.60500   -1.47200   86.90780    0.14560   -0.00150    0.14560    0.28860    0.14560   14.14280    0.26460    1.00000    0.00000    0.14560    0.00000   14.14280    0.00000    0.00000    0.00000\n",
      "Line 59:  909.75000    -999.25 2692.81370    0.27300   22.59090   22.59090   13.68210   12.61460   -1.48040   89.84920  201.92870    3.15510    -999.25    -999.25    4.31240    -999.25    1.92870 2976.44510 2976.44510   -1.48040   86.34650    0.14350    0.01010    0.14350    0.27300    0.14350   14.56740    0.25980    1.00000    0.00000    0.14350    0.00000   14.56740    0.00000    0.00000    0.00000\n",
      "Line 60:  909.62500    -999.25 2644.36500    0.27650   18.48310   18.48310   13.41590   12.69000   -1.50100   93.39990  201.58260   -6.58610    -999.25    -999.25    4.38220    -999.25    1.58260 2955.35280 2955.35280   -1.50100   89.71420    0.15900    0.03840    0.15900    0.27650    0.15900   11.86000    0.32100    0.96670    0.00000    0.15380    0.00000   11.86000    0.00000    0.00000    0.00000\n",
      "Line 61:  909.50000    -999.25 2586.28220    0.29960   13.91870   13.91870   12.91950   12.70160   -1.49160   98.12140  201.71260   -4.55740    -999.25    -999.25    3.59670    -999.25    1.71260 2953.59400 2953.59400   -1.49160   94.26700    0.18800    0.07230    0.18800    0.29960    0.18800    8.48630    0.44900    0.81740    0.00000    0.15370    0.00000    8.48630    0.00000    0.00000    0.00000\n"
     ]
    }
   ],
   "source": [
    "l.version[\"WRAP\"].value = \"NO\"\n",
    "print l.version[\"WRAP\"]\n",
    "print\n",
    "s = lasio.las.StringIO()\n",
    "l.write(s, version=2, fmt=\"%.5f\")\n",
    "s.seek(0)\n",
    "print2(s.read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
